<?php

/**

 * 同城微聚汇

 * ============================================================================

 * 版权所有 2015-2027 武汉鼎联信息技术有限公司，并保留所有权利。

 * 网站地址: http://dlshop.dliansoft.com

 * ----------------------------------------------------------------------------

 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .

 * 不允许对程序代码以任何形式任何目的的再发布。

 * ============================================================================

 * Author: wangqh

 * Date: 2015-09-09

 *  阿里大鱼短信模板管理

 */

namespace app\admin\controller;
use think\AjaxPage;
use think\Page;
use think\Db;

class WxMessage extends Base {
     /*
     * 微信消息任务列表
     */
    public function index(){
        $adminId = getAdminId();
        $where = array();
        if($adminId['suppliers_id']){
            $where['suppliers_id'] = $adminId['suppliers_id'];
        }
        $count =  M('wx_template_msg')->where($where)->count();
        $Page = new Page($count,10);
        $show = $Page->show();
        $lists = M('wx_template_msg')->where($where)->order('createtime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('lists',$lists);
        $this->assign('pager',$Page);// 赋值分页输出
        $this->assign('page',$show);// 赋值分页输出   
        return $this->fetch();
    }

    
    /*
     * 添加编辑一个优惠券类型
     */
    public function wxmessage_info(){
        $adminId = getAdminId();
        if(IS_POST){
            $data = I('post.');
            $data['user_list']=base64_encode($data['user_list']);
            $data['admin_id']= $adminId['admin_id'];
            $data['suppliers_id']= $adminId['suppliers_id'];
            if(empty($data['id'])){
                $data['createtime'] = time();
                $row = M('wx_template_msg')->add($data);
            }else{
                $row =  M('wx_template_msg')->where(array('id'=>$data['id']))->save($data);
            }
            if(!$row&&$row!=0)
                $this->error('编辑微信消息失败');
            $this->success('编辑微信消息成功',U('Admin/WxMessage/index'));
            exit;
        }
        $cid = I('get.id/d');
        if($cid){
            $wxmessage = M('wx_template_msg')->where(array('id'=>$cid))->find();
           $this->assign('wxmessage',$wxmessage);
            
        }
        $template = M('wx_template')->select();
        
        $this->assign('temps',$template);
        return $this->fetch();
    }

        public function select_user(){
            $cid = I('cid/d');
            $this->assign('cid',$cid);
            return $this->fetch();
        }

    public function ajax_get_user(){
        //搜索条件
        $condition = array();
        I('mobile') ? $condition['mobile'] = I('mobile') : false;
        I('email') ? $condition['email'] = I('email') : false;
        $nickname = I('nickname');
        if(!empty($nickname)){
            $condition['nickname'] = array('like',"%$nickname%");
        }
        $model = M('users');
        $count = $model->where($condition)->count();
        $Page  = new AjaxPage($count,10);
        foreach($condition as $key=>$val) {
            $Page->parameter[$key] = urlencode($val);
        }
        $show = $Page->show();
        $userList = $model->where($condition)->order("user_id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
        
        $user_level = M('user_level')->getField('level_id,level_name',true);       
        $this->assign('user_level',$user_level);
        $this->assign('userList',$userList);
        $this->assign('page',$show);
        $this->assign('pager',$Page);
        return $this->fetch();
    }

public function details_list()
    {
        $where = array();
        $id = I('id');
        if($id){
            $where['t_id'] = $id;
        }
        $count =  M('wx_template_msg_list')->where($where)->count();
        $Page = new Page($count,10);
        $show = $Page->show();
        $lists = M('wx_template_msg_list')->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('lists',$lists);
        $this->assign('pager',$Page);// 赋值分页输出
        $this->assign('page',$show);// 赋值分页输出
        return $this->fetch();
    }




}